package pers.itqiqi.dao.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import pers.itqiqi.dao.UserDao;
import pers.itqiqi.pojo.User;

/**
 * @author kevin_琪琪
 * @version 1.0
 * @description UserDaoImpl实现类
 * @date 2022-07-08 09:22
 */

@Repository
public class UserDaoImpl implements UserDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 修改用户金钱
     * @param money 金钱
     * @param userId 要修改的用户id
     */
    @Override
    public void updateMoney(Long money, Long userId) {
        String sql = "update test.test_user_money set money=? where userId=?";
        jdbcTemplate.update(sql, money, userId);
    }

    /**
     * 获取用户当前的金钱数
     * @param userId 用户id
     */
    @Override
    public Long queryMoney(Long userId) {
        String sql = "select money from test.test_user_money where userId=?";
        return jdbcTemplate.queryForObject(sql, Long.class, userId);
    }
}
